<script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router'
const router = useRouter()

interface PayItem {
  icon: 'wechat' | 'alipay' | 'bank' | 'apple'
  label: string
  value: string
  price: number
}

const payList: PayItem[] = [
  { icon: 'wechat', label: '微信支付', value: 'wechat', price: 2430.0 },
  { icon: 'alipay', label: '支付宝支付', value: 'alipay', price: 2430.0 },
  { icon: 'bank', label: '建设银行 5028', value: 'bank', price: 2410.0 },
  { icon: 'apple', label: '苹果账号支付', value: 'apple', price: 2410.0 }
]
const selected = ref<string>('wechat')

function selectPay(val: string): void {
  selected.value = val
}
function goBack(): void {
  router.back()
}
function addPayMethod(): void {
  // 可扩展：弹窗或跳转添加新方式
}
function confirmPay(): void {
  router.push({ name: 'PayTJ' })
}
</script>

<template>
  <div class="pay-view">
    <div class="pay-header">
      <span class="pay-back" @click="goBack">←</span>
      <span class="pay-title">选择支付方式</span>
    </div>
    <div class="pay-list">
      <div class="pay-item" v-for="item in payList" :key="item.value" :class="{selected: selected === item.value}" @click="selectPay(item.value)">
        <span class="pay-icon">
          <template v-if="item.icon==='wechat'">
            <svg width="28" height="28" viewBox="0 0 48 48" fill="none"><circle cx="24" cy="24" r="24" fill="#fff"/><ellipse cx="16.5" cy="27" rx="8.5" ry="7" fill="#7bb32e"/><ellipse cx="31.5" cy="21" rx="10.5" ry="9" fill="#7bb32e"/><circle cx="19" cy="25" r="1.5" fill="#fff"/><circle cx="28" cy="20" r="1.5" fill="#fff"/></svg>
          </template>
          <template v-else-if="item.icon==='alipay'">
            <svg width="28" height="28" viewBox="0 0 48 48" fill="none"><circle cx="24" cy="24" r="24" fill="#fff"/><path d="M12 24c0-6.627 5.373-12 12-12s12 5.373 12 12-5.373 12-12 12S12 30.627 12 24Z" fill="#1677ff"/><path d="M18 24h12M24 18v12" stroke="#fff" stroke-width="2" stroke-linecap="round"/></svg>
          </template>
          <template v-else-if="item.icon==='bank'">
            <svg width="28" height="28" viewBox="0 0 48 48" fill="none"><circle cx="24" cy="24" r="24" fill="#fff"/><rect x="12" y="20" width="24" height="12" rx="2" fill="#222"/><rect x="18" y="26" width="12" height="2" rx="1" fill="#fff"/></svg>
          </template>
          <template v-else-if="item.icon==='apple'">
            <svg width="28" height="28" viewBox="0 0 48 48" fill="none"><circle cx="24" cy="24" r="24" fill="#fff"/><path d="M32 32c-1.5 2-3.5 2-4.5 2s-3-.5-4.5-2c-2-2-3-4.5-3-7.5C20 20 24 20 24 20s4 0 4 4.5c0 3-1 5.5-3 7.5Z" fill="#222"/><circle cx="24" cy="18" r="2" fill="#222"/></svg>
          </template>
        </span>
        <span class="pay-label">{{ item.label }}</span>
        <span class="pay-price">¥{{ item.price.toFixed(1) }}</span>
        <span class="pay-radio">
          <span v-if="selected === item.value" class="radio checked"></span>
          <span v-else class="radio"></span>
        </span>
      </div>
    </div>
    <button class="pay-confirm" @click="confirmPay">确认支付</button>
  </div>
</template>

<style scoped>
.pay-view {
  background: #fff;
  min-height: 100vh;
  font-family: 'PingFang SC', 'Microsoft YaHei', Arial, sans-serif;
}
.pay-header {
  display: flex;
  align-items: center;
  height: 56px;
  padding: 0 16px;
  font-size: 20px;
  font-weight: bold;
  position: relative;
  background: #fff;
  justify-content: center;
}
.pay-back {
  font-size: 26px;
  margin-right: 8px;
  cursor: pointer;
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
}
.pay-title {
  flex: 1;
  text-align: center;
  font-size: 20px;
  font-weight: bold;
}
.pay-add {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  cursor: pointer;
  display: flex;
  align-items: center;
}
.pay-list {
  margin: 32px 0 0 0;
  display: flex;
  flex-direction: column;
  gap: 28px;
}
.pay-item {
  display: flex;
  align-items: center;
  background: #fff;
  box-shadow: 0 4px 24px 0 rgba(0,0,0,0.07);
  border-radius: 32px;
  padding: 18px 24px;
  margin: 0 16px;
  cursor: pointer;
  transition: box-shadow 0.2s;
  position: relative;
}
.pay-item.selected {
  box-shadow: 0 4px 24px 0 rgba(17,17,17,0.13);
}
.pay-icon {
  width: 36px;
  height: 36px;
  margin-right: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pay-label {
  font-size: 18px;
  font-weight: 600;
  color: #111;
  flex: 1;
}
.pay-price {
  font-size: 18px;
  font-weight: 600;
  color: #111;
  margin-right: 16px;
}
.pay-radio {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.radio {
  width: 24px;
  height: 24px;
  border: 2px solid #bdbdbd;
  border-radius: 50%;
  display: inline-block;
  background: #fff;
  position: relative;
}
.radio.checked {
  border: 2px solid #111;
}
.radio.checked::after {
  content: '';
  display: block;
  width: 12px;
  height: 12px;
  background: #111;
  border-radius: 50%;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
.pay-confirm {
  width: 92vw;
  max-width: 600px;
  height: 64px;
  background: #111;
  color: #fff;
  font-size: 20px;
  font-weight: bold;
  border: none;
  border-radius: 32px;
  box-shadow: 0 2px 12px 0 rgba(0,0,0,0.08);
  cursor: pointer;
  letter-spacing: 2px;
  margin: 48px auto 0 auto;
  display: block;
}
</style>